package ligafutbol;

import javax.swing.*;
import javax.swing.tree.*;
import java.util.*;
import clases.*;
import java.util.ArrayList;

public class frmMostrarJornadas extends javax.swing.JFrame {

    /** Creates new form frmMostrarJornadas */
    public frmMostrarJornadas() {
        initComponents();

        DefaultMutableTreeNode raiz = new DefaultMutableTreeNode("Jornadas");

        ArrayList<Jornada> listaJornada = Jornada.verTodasJornada();
        Iterator it = listaJornada.iterator();
        while(it.hasNext()){
            Jornada jornada = (Jornada)it.next();
            DefaultMutableTreeNode nodoJornada = new DefaultMutableTreeNode("Jornada "+jornada.getNumJornada());
            ArrayList<Partido>listaPartido = Partido.partidosJornada(jornada);

            Iterator it2 = listaPartido.iterator();
            while(it2.hasNext()){
                Partido partido = (Partido)it2.next();
                DefaultMutableTreeNode nodoPartido = new DefaultMutableTreeNode(partido);
                nodoJornada.add(nodoPartido);
            }

            raiz.add(nodoJornada);
        }

        this.treeJornadas.setModel(new DefaultTreeModel(raiz));


    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jScrollPane1 = new javax.swing.JScrollPane();
        treeJornadas = new javax.swing.JTree();
        lbTitulo = new javax.swing.JLabel();
        btnVolver = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        javax.swing.tree.DefaultMutableTreeNode treeNode1 = new javax.swing.tree.DefaultMutableTreeNode("root");
        treeJornadas.setModel(new javax.swing.tree.DefaultTreeModel(treeNode1));
        jScrollPane1.setViewportView(treeJornadas);

        lbTitulo.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        lbTitulo.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        lbTitulo.setText("VER JORNADAS");

        btnVolver.setText("<< Volver");
        btnVolver.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnVolverActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(62, 62, 62)
                .addComponent(lbTitulo, javax.swing.GroupLayout.PREFERRED_SIZE, 290, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(48, Short.MAX_VALUE))
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap(168, Short.MAX_VALUE)
                .addComponent(btnVolver)
                .addGap(159, 159, 159))
            .addGroup(layout.createSequentialGroup()
                .addGap(76, 76, 76)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 240, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(84, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(28, 28, 28)
                .addComponent(lbTitulo)
                .addGap(29, 29, 29)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 146, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 35, Short.MAX_VALUE)
                .addComponent(btnVolver)
                .addGap(22, 22, 22))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void btnVolverActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnVolverActionPerformed
        // TODO add your handling code here:
        this.setVisible(false);
    }//GEN-LAST:event_btnVolverActionPerformed

    /**
    * @param args the command line arguments
    */
    public static void inicio() {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new frmMostrarJornadas().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnVolver;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JLabel lbTitulo;
    private javax.swing.JTree treeJornadas;
    // End of variables declaration//GEN-END:variables

}
